/* matrix.hpp
#include <iostream>
#include <cstring>

using namespace std;

class Matrix {
public:
        Matrix() :rows(0), cols(0), data(NULL) {}
        Matrix(int rows, int cols) :rows(rows), cols(cols) {
                data = new int[rows * cols];
        }
        ~Matrix() {
                delete[] data;
        }

        int* operator[](int );
        const int* operator[](int ) const;
        friend int sum(const Matrix& matrix);
        friend istream& operator>>(istream& is, Matrix& matrix);
        friend ostream& operator<<(ostream& os, const Matrix& matrix);
private:
        int rows, cols;
        int* data;
};
*/

#include "matrix.hpp"

#include <iostream>

using namespace std;

int* Matrix::operator[](int i) {
    return data + i * cols;
}

const int* Matrix::operator[](int i) const {
    return data + i * cols;
}

int sum(const Matrix& m) {
    int sum = 0;
    for (int i = 0; i < m.rows; ++i) {
        for (int j = 0; j < m.cols; ++j) {
            sum += m[i][j];
        }
    }
    return sum;
}

istream& operator>>(istream& is, Matrix& m) {
    for (int i = 0; i < m.rows; ++i) {
        for (int j = 0; j < m.cols; ++j) {
            is >> m[i][j];
        }
    }
    return is;
}

ostream& operator<<(ostream& os, const Matrix& m) {
    cout << "Matrix:" << endl;
    for (int i = 0; i < m.rows; ++i) {
        for (int j = 0; j < m.cols; ++j) {
            os << m[i][j] << " ";
        }
        os << endl;
    }
    return os;
}
